import prompt from '@system.prompt';
import router from '@system.router';
export default {
    data: {
//        "mini": 20,
        "busList": [
            {"id": 1, "busNum": "987路", "waitingStation": "海珠客运站", "endStation": "天安科技园", "timeRemaining": 5, "stationsRemaining": 1, "kmRemaining": 1.5}
            ,{"id": 2, "busNum": "303路", "waitingStation": "海珠客运站", "endStation": "市桥汽车站", "timeRemaining": 20, "stationsRemaining": 3, "kmRemaining": 3.5},
            {"id": 3, "busNum": "129路", "waitingStation": "海珠客运站", "endStation": "市桥汽车站", "timeRemaining": 20, "stationsRemaining": 3, "kmRemaining": 3.5},
            {"id": 4, "busNum": "303路", "waitingStation": "海珠客运站", "endStation": "市桥汽车站", "timeRemaining": 20, "stationsRemaining": 3, "kmRemaining": 3.5},
            {"id": 5, "busNum": "303路", "waitingStation": "海珠客运站", "endStation": "市桥汽车站", "timeRemaining": 20, "stationsRemaining": 3, "kmRemaining": 3.5},
            {"id": 6, "busNum": "303路", "waitingStation": "海珠客运站", "endStation": "市桥汽车站", "timeRemaining": 20, "stationsRemaining": 3, "kmRemaining": 3.5}
        ],
        "keyword": ""
    },
    onInit() {
        this.getBusList();
    },
    initAction: function (code) {
        var actionData = {"keyword": this.keyword};
        var action = {};
        action.bundleName = "com.army.study";
        action.abilityName = "com.army.study.service.BusInternalAbility";
        action.messageCode = code;
        action.data = actionData;
        action.abilityType = 1;
        action.syncOption = 0;
        return action;
    },
    getBusList: async function () {
        try {
            var action = this.initAction(1001);
            var result = await FeatureAbility.callAbility(action);
            console.info(" @@result = " + JSON.stringify(result));
            this.busList = JSON.parse(result);
        } catch (pluginError) {
            console.error("getBusList : Plugin Error = " + pluginError);
        }
    },
    change(e) {
        this.keyword = e.value;
        this.getBusList();
    },
    open(id) {
        router.push ({
            uri:'pages/details/details',
            params: {
                id: id
            }
        });
    }
}
